package engine;

import utils.Point;

@SuppressWarnings("unused")
class Dynamic extends Spritable {

	private Point pos = new Point(0, 0), spd = new Point(0, 0);
	private Point acc = new Point(0, 0), frc = new Point(0, 0);

	public boolean isAtRest() {
		return getXSpd() == 0 && getYSpd() == 0;
	}

	public boolean isAtCompleteRest() {
		return isAtRest() && getXAcc() == 0 && getYAcc() == 0;
	}

	public float getXPos() {
		return pos.getX();
	}

	public float getYPos() {
		return pos.getY();
	}

	public float getXSpd() {
		return spd.getX();
	}

	public float getYSpd() {
		return spd.getY();
	}

	public float getXAcc() {
		return acc.getX();
	}

	public float getYAcc() {
		return acc.getY();
	}

	public float getXFrc() {
		return frc.getX();
	}

	public float getYFrc() {
		return frc.getY();
	}

	public void setXPos(float xPos) {
		Point prevP = pos;
		pos = pos.set(xPos, pos.getY());
		moved(prevP, pos);
	}

	public void setYPos(float yPos) {
		Point prevP = pos;
		pos = pos.set(pos.getX(), yPos);
		moved(prevP, pos);
	}

	public void setXSpd(float xSpd) {
		spd = spd.set(xSpd, spd.getY());
	}

	public void setYSpd(float ySpd) {
		spd = spd.set(spd.getX(), ySpd);
	}

	public void setSpd(float abs, double angle) {
		spd = new Point(abs, angle * Math.PI / 180);
	}

	public void setXAcc(float xAcc) {
		acc = acc.set(xAcc, acc.getY());
	}

	public void setYAcc(float yAcc) {
		acc = acc.set(acc.getX(), yAcc);
	}

	public void setXFrc(float xFrc) {
		frc = frc.set(xFrc, frc.getY());
	}

	public void setYFrc(float yFrc) {
		frc = frc.set(frc.getX(), yFrc);
	}

	//

	protected Point getPos() {
		return pos;
	}

	protected Point getSpd() {
		return spd;
	}

	protected Point getAcc() {
		return acc;
	}

	protected Point getFrc() {
		return frc;
	}

	private void setPos(Point pos) {
		this.pos = pos;
	}

	private void setSpd(Point spd) {
		this.spd = spd;
	}

	private void setAcc(Point acc) {
		this.acc = acc;
	}

	private void setFrc(Point frc) {
		this.frc = frc;
	}

	public void bounce(Point frc) {
		spd = spd.set(spd.negate()).add(frc.multiply(spd));
	}

	protected void moved(Point from, Point to) {}

	public void step(Room room, float fpsFactor) {
		super.step(fpsFactor);
		setSpd(getSpd().add(getFrc().multiply(getSpd()).subtract(getAcc()).negate().multiply(fpsFactor)));
		setPos(getPos().add(getSpd().multiply(fpsFactor)));
	}

}
